//
//  HNMyController.m
//  shezhan
//
//  Created by admin on 16/8/13.
//  Copyright © 2016年 haoniu. All rights reserved.
//

#import "HNMyController.h"
#import "ApplyViewController.h"
#import "ChatViewController.h"
#import "HNMainController.h"
#import "ChatDemoHelper.h"
#import "HNShareController.h"
#import "HNConcernController.h"
#import "UIActionSheet+Blocks.h"

@interface HNMyController ()<UIWebViewDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,HNSettingJSExport,UIActionSheetDelegate>{
    NSDictionary * _userInfo;
}
@property (nonatomic,retain) UIImagePickerController * imagePicker;
@property (nonatomic,strong) NSString *urlStr;
@end

@implementation HNMyController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSString * _loginName = [NSString stringWithFormat:@"%@",[AppConfig getUserInfoByKey:@"hnLoginName"]];
    _webViewUrl = [NSMutableString stringWithFormat:@"%@%@?hnLoginName=%@",url_Base,url_My,_loginName];
    _webViewUrl = [NSMutableString stringWithFormat:@"%@",[_webViewUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSURLRequest * _req = [NSURLRequest requestWithURL:[NSURL URLWithString:_webViewUrl]];
    _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 20, mainScreenSize.width, mainScreenSize.height-70)];
    _webView.scrollView.bounces = YES;
    //_webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin;
    _webView.autoresizesSubviews = YES;
    _webView.delegate = self;
    [_webView setBackgroundColor:[AppConfig colorWithHexString:@"#ececec"]];
    [self.view addSubview:_webView];
    [_webView loadRequest:_req];
    
//    UIButton * buttonLeft = [[UIButton alloc]initWithFrame:CGRectMake(8, 20, 44, 44)];
//    [buttonLeft setTitle:@"LEFT" forState:UIControlStateNormal];
//    [buttonLeft setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//    [self.view addSubview:buttonLeft];
//    
//    CGRect rect = [UIApplication sharedApplication].keyWindow.bounds;
//    UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(64, 20, rect.size.width-128, 44)];
//    [titleLabel setText:@"首页"];
//    [titleLabel setTextColor:[UIColor redColor]];
//    [titleLabel setTextAlignment:NSTextAlignmentCenter];
//    [self.view addSubview:titleLabel];
//    
//    UIButton * buttonRight = [[UIButton alloc]initWithFrame:CGRectMake(rect.size.width-64, 20, 54, 44)];
//    [buttonRight setTitle:@"RIGHT" forState:UIControlStateNormal];
//    [buttonRight setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//    [self.view addSubview:buttonRight];

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma -mark WebView
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    NSLog(@"WebView erros is %@",error);
    if ([error code] == NSURLErrorCancelled) {
        return;
    }
    // 应用场景:加载从服务器上下载的文件,例如pdf,或者word,图片等等文件
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"error" ofType:@"html"];
    NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    NSLog(@"====webViewDidFinishLoad");
        if([self.urlStr containsString:url_My]&&[self.urlStr containsString:url_PersonalInfo]){
            NSLog(@"ahhahahahahhahahahahhahahahhaahahhahahhahah");
            self.urlStr = nil;
            [self.webView reload];
        }
    // Disable user selection
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
    // Disable callout
    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
    
    //JS交互
    JSContext *context=[webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    context[@"JavaScriptInterface"] = self;
}
- (BOOL)webView: (UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
  
    NSString *urlStr = [[request URL] absoluteString];
    
     NSLog(@"urlStr==%@",urlStr);
    
    //一组if-else判断，设定修改头像后，返回我的主页面刷新的条件
    if([urlStr containsString:url_PersonalInfo] && [AppConfig isNULL:self.urlStr]){
        self.urlStr = url_PersonalInfo;
    }else if([self.urlStr isEqualToString:url_PersonalInfo]&&[urlStr containsString:url_My]){
        self.urlStr = [self.urlStr stringByAppendingString:url_My];
    }
    
    NSLog(@"fdjsfhjfdhsj==%@",self.urlStr);
    
    if([urlStr containsString:url_GuanZhu]){
        HNConcernController *concernVC = [[HNConcernController alloc]init];
        concernVC.type = @"1";
        [self.navigationController pushViewController:concernVC animated:YES];
        return NO;
    }
    
    
    NSLog(@"=============123:%@",request);
    if ([[urlStr substringToIndex:5] isEqualToString:@"file:"]) {
        return YES;
    }else if ([urlStr isEqualToString:_webViewUrl]) {
       // _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 20, mainScreenSize.width, mainScreenSize.height-70)];
        //创建一个消息对象
        NSNotification * notice = [NSNotification notificationWithName:@"HNMainControllerNotification" object:nil userInfo:@{@"tabbarShow":@"1",@"controller":@"my"}];
        //发送消息
        [[NSNotificationCenter defaultCenter]postNotification:notice];
        return YES;
    }
    //_webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 20, mainScreenSize.width, mainScreenSize.height-20)];
    //创建一个消息对象
    NSNotification * notice = [NSNotification notificationWithName:@"HNMainControllerNotification" object:nil userInfo:@{@"tabbarShow":@"0",@"controller":@"my"}];
    //发送消息
    [[NSNotificationCenter defaultCenter]postNotification:notice];
    return YES;
}

#pragma -mark 设置退出 HNSettingJSExport

-(void)HNSettingJSExportOutLogin{
    NSLog(@"HNSettingJSExportOutLogin");
    __weak HNMyController *weakSelf = self;
    [self showHudInView:self.view hint:@"退出登陆"];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        EMError *error = [[EMClient sharedClient] logout:YES];
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf hideHud];
            if (error != nil) {
                [weakSelf showHint:error.errorDescription];
                NSLog(@"error.errorDescription = %@",error.errorDescription);
            }
            else{
                [self cancelTag];
                [[ApplyViewController shareController] clear];
                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@NO];
            }
        });
    });
}

-(void)cancelTag{
    
//    NSString * loginName = [NSString stringWithFormat:@"%@",[AppConfig getUserInfoByKey:@"hnLoginName"]];
//    NSMutableSet *set  = [[NSMutableSet alloc]initWithObjects:loginName, nil];
    [AppConfig cancelTags:nil andcancelAlias:nil];
}

#pragma mark - HNSettingUserImageJSExport 上传头像
-(void)HNSettingJSExportOutChangeUserImage{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        
        dispatch_async(dispatch_get_main_queue(),^{
            UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"更换头像" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择", @"拍照", nil];
            actionSheet.delegate = self;
            actionSheet.tag = 1001;
            [actionSheet showInView:self.webView];
            self.imagePicker = [[UIImagePickerController alloc]init];
            self.imagePicker.delegate = self;
            self.imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
            self.imagePicker.allowsEditing = YES;
        });
    });
    
   
}

#pragma mark - 判断设备是否有摄像头
- (BOOL) isCameraAvailable
{
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}
#pragma mark - UIActionSheet delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    
    if (actionSheet.tag==1001) {
        _imagePicker = [[UIImagePickerController alloc] init];
        _imagePicker.editing = YES;
        _imagePicker.allowsEditing = YES;
        _imagePicker.delegate = self;
        if (buttonIndex == 0)
        {
            //相册
            _imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            //[self presentModalViewController:_imagePicker animated:YES];
            [self presentViewController:_imagePicker animated:YES completion:nil];
            
        }else if (buttonIndex == 1){
            //照相机
            if ([self isCameraAvailable]) {
                _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
                //[self presentModalViewController:_imagePicker animated:YES];
                [self presentViewController:_imagePicker animated:YES completion:nil];
            }else{
                [self showHint:@"该设备没有摄像头"];
            }
        }else
        {
            //取消
        }
    }
    
}
#pragma mark - UIImagePicker delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    //[picker dismissModalViewControllerAnimated:YES];
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    //UIImage *image = [[info objectForKey:UIImagePickerControllerEditedImage] retain];
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    [self performSelector:@selector(saveImage:) withObject:image afterDelay:0.5];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
//    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
    //[picker dismissModalViewControllerAnimated:YES];
    //保持状态栏颜色---为黑色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    [picker dismissViewControllerAnimated:YES completion:nil];
}

//上传图片
-(void)saveImage:(UIImage *)image{
    NSLog(@"image = %@",image);
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:url_Base]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager POST:url_UpdateUserImage parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
        //压缩图片
        
        __block UIImage * changeImage = [self compressImage:image toTargetWidth:333];
        
        NSData *data = UIImagePNGRepresentation(changeImage);

      NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
      // 设置时间格式
        formatter.dateFormat = @"yyyyMMddHHmmss";
        NSString *str = [formatter stringFromDate:[NSDate date]];
        NSString *fileName = [NSString stringWithFormat:@"%@.png", str];
        [formData appendPartWithFileData:data name:@"file" fileName:fileName mimeType:@"image/png"];
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        //打印下上传进度
        NSLog(@"上传进度");
        NSLog(@"%@",uploadProgress);
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //上传成功
        NSLog(@"上传成功");
        NSError *error;
        NSDictionary * data = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        [self hideHud];
        if (error) {
            NSLog(@"====error1:%@",error);
            return;
        }
        NSLog(@"==dict:%@",data);
        NSDictionary *userImageDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@",[data objectForKey:@"imgUrl"]],@"imgUrl", nil];

         NSLog(@"userImageDic =  %@",userImageDic);
        
        dispatch_async(dispatch_get_main_queue(), ^{
            NSString *dicStr = [NSString stringWithFormat:@"%@",[AppConfig dictionaryToJson:userImageDic]];
            NSLog(@"dicStr =  %@",dicStr);
            //调用JS 的方法
            NSString *str = [self.webView  stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"upLoadSuccess(%@);",dicStr]];

            NSLog(@"str =  %@",str);
        });
     

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        //上传失败
        NSLog(@"上传失败");
        NSLog(@"%@",error.description);
    }];
    
}

//压缩图片
- (UIImage *)compressImage:(UIImage *)sourceImage toTargetWidth:(CGFloat)targetWidth {
    CGSize imageSize = sourceImage.size;
    
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    
    NSLog(@"width = %f,height = %f",width,height);
    
    CGFloat targetHeight = (targetWidth / width) * height;
    NSLog(@"targetWidth = %f targetHeight = %f",targetWidth,targetHeight);
    
    UIGraphicsBeginImageContext(CGSizeMake(targetWidth, targetHeight));
    [sourceImage drawInRect:CGRectMake(0, 0, targetWidth, targetHeight)];
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return newImage;
}
#pragma -mark HNMyJSExport - 在线客服

-(void)HNMyJSExportOnlineService{
    NSLog(@"在线客服");
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        //设置标题和跳转
        [self setTitle:[NSString stringWithFormat:@"%ld",on_lineServiceTelPhone] andJsonStr:nil];
    });
  
}

#pragma -mark HNPublishProductJSExport - 设置返回
-(void)HNPublishProductJSExportBack{
    if ([self.webView canGoBack]) {
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            dispatch_async(dispatch_get_main_queue(),^{
                NSLog(@"回归主线程");
                [self.view resignFirstResponder];
                [self.webView goBack];
            });
        });
  
        
    }else{
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            dispatch_async(dispatch_get_main_queue(),^{
                NSLog(@"回归主线程");
                [self.view resignFirstResponder];
                [self.navigationController popViewControllerAnimated:YES];
            });
        });
    }
    NSLog(@"-------goBack---------");
}

-(NSString *)HNPublishProductJSExportReturnLoginName{
    return [[EMClient sharedClient] currentUsername];
}

#pragma -mark JS返回登录结果
-(void)HNLoginJSExportLoginResult:(NSNumber *)success WithUserInfo:(NSString *)data{
    NSLog(@"HNLoginJSExportLoginResult:%@,%@",success,data);
    NSDictionary *userInfo = [AppConfig dictionaryWithJsonString:data];
    _userInfo = userInfo;
    if (_userInfo) {
        [self loginWithUsername:[_userInfo objectForKey:@"hnLoginName"] password:[_userInfo objectForKey:@"hnLoginPwd"]];
        //[self loginWithUsername:@"duhuan" password:@"123456"];
    }
    
}

#pragma -mark 登录环信
//点击登陆后的操作
- (void)loginWithUsername:(NSString *)username password:(NSString *)password
{
    [self showHudInView:self.view hint:nil];//NSLocalizedString(@"login.ongoing", @"Is Login...")
    //异步登陆账号 
    __weak typeof(self) weakself = self;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        EMError *error = [[EMClient sharedClient] loginWithUsername:username password:password];
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakself hideHud];
            if (!error) {
                //设置是否自动登录
                [[EMClient sharedClient].options setIsAutoLogin:YES];
                
                //获取数据库中数据
                [self showHudInView:self.view hint:nil];
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                    [[EMClient sharedClient] dataMigrationTo3];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [[ChatDemoHelper shareHelper] asyncGroupFromServer];
                        [[ChatDemoHelper shareHelper] asyncConversationFromDB];
                        [[ChatDemoHelper shareHelper] asyncPushOptions];
                        [self hideHud];
                        //发送自动登陆状态通知
//                        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@([[EMClient sharedClient] isLoggedIn])];
                      HNMainController  *mainController = [[HNMainController alloc] init];
                        [self.navigationController pushViewController:mainController animated:YES];
                        
                        //保存最近一次登录用户名
                        [weakself saveLastLoginUsername];
                        [AppConfig saveUserInfo:_userInfo];
//                        [self downLoadUserInfo:username];
                        
                    });
                });
            } else {
                switch (error.code)
                {
                        //                    case EMErrorNotFound:
                        //                        TTAlertNoTitle(error.errorDescription);
                        //                        break;
                    case EMErrorNetworkUnavailable:
                        TTAlertNoTitle(NSLocalizedString(@"error.connectNetworkFail", @"No network connection!"));
                        break;
                    case EMErrorServerNotReachable:
                        TTAlertNoTitle(NSLocalizedString(@"error.connectServerFail", @"Connect to the server failed!"));
                        break;
                    case EMErrorUserAuthenticationFailed:
                        TTAlertNoTitle(error.errorDescription);
                        break;
                    case EMErrorServerTimeout:
                        TTAlertNoTitle(NSLocalizedString(@"error.connectServerTimeout", @"Connect to the server timed out!"));
                        break;
                    default:
                        TTAlertNoTitle(NSLocalizedString(@"login.fail", @"Login failure"));
                        break;
                }
            }
        });
    });
}

//-(void)downLoadUserInfo:(NSString *)loginName{
//    //刷新加载头像数据
//    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:loginName,@"hnLoginName", nil];
//    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:url_Base]];
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//    [manager POST:url_UserInfo parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
//        
//    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSError * error;
//        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
//        [self hideHud];
//        if (error) {
//            NSLog(@"====error1:%@",error);
//            return;
//        }
//        NSLog(@"==dict:%@",data);
//        NSString * code = [NSString stringWithFormat:@"%@",[data objectForKey:@"error"]];
//        if ([code isEqualToString:@"0"]) {
//            NSDictionary *userInfo = [data objectForKey:@"data"];
//            
//            NSString *loginName = [NSString stringWithFormat:@"%@",[userInfo objectForKey:@"hnLoginName"]];
//            if ([AppConfig isNULL:loginName]) {
//                loginName = @"";
//            }
//            NSMutableDictionary *peopleDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:loginName,@"hnLoginName", nil];
//            
//            NSString *head = [NSString stringWithFormat:@"%@",[userInfo objectForKey:@"hnHead"]];
//            if ([AppConfig isNULL:head]) {
//                head = @"";
//            }
//            [peopleDic setObject:head forKey:@"hnHead"];
//            NSString *nickName = [NSString stringWithFormat:@"%@",[userInfo objectForKey:@"hnNickName"]];
//            if ([AppConfig isNULL:nickName]) {
//                nickName = @"";
//            }
//            [peopleDic setObject:nickName forKey:@"hnNickName"];
//            NSLog(@"peopleDic = %@",peopleDic);
//            [AppConfig savePeopleInfo:peopleDic];
//            
//        }else{
//            //            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"message"]];
//            //            [self showHint:info];
//        }
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull   error) {
//        NSLog(@"====error:%@",error);
//        [self hideHud];
//        //        [self showHint:@"获取用户信息失败"];
//    }];
//
//}


#pragma  mark - private
- (void)saveLastLoginUsername
{
    NSString *username = [[EMClient sharedClient] currentUsername];
    if (username && username.length > 0) {
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        [ud setObject:username forKey:[NSString stringWithFormat:@"em_lastLogin_username"]];
        [ud synchronize];
    }
}

- (NSString*)lastLoginUsername
{
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    NSString *username = [ud objectForKey:[NSString stringWithFormat:@"em_lastLogin_username"]];
    if (username && username.length > 0) {
        return username;
    }
    return nil;
}

#pragma -mark HNGoodsDetailJSExport - 联系商家
-(void)HNGoodsDetailJSExportContactMerchantResult:(NSString *)merchantPhone :(NSString *)goodsJsonStr{
    NSLog(@"联系商家 merchantPhone = %@, goodsJsonStr = %@",merchantPhone,goodsJsonStr);
    if(merchantPhone.length <= 1){
        [self showHint:@"无此用户"];
    }
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        //设置标题和跳转
        [self setTitle:merchantPhone andJsonStr:goodsJsonStr];
    });
}

-(void)setTitle:(NSString *)merchantPhone andJsonStr:(NSString *)goodsJsonStr{
    //刷新加载头像数据
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:merchantPhone,@"hnLoginName", nil];
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:url_Base]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:url_UserInfo parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSError * error;
        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        [self hideHud];
        if (error) {
            NSLog(@"====error1:%@",error);
            return;
        }
        NSLog(@"==dict:%@",data);
        NSString * code = [NSString stringWithFormat:@"%@",[data objectForKey:@"error"]];
        if ([code isEqualToString:@"0"]) {
            NSDictionary *userInfo = [data objectForKey:@"data"];
            ChatViewController *chatController = [[ChatViewController alloc] initWithConversationChatter:merchantPhone conversationType:EMConversationTypeChat];
            chatController.title = [NSString stringWithFormat:@"%@",[userInfo objectForKey:@"hnNickName"]];
            chatController.goodsJsonStr = goodsJsonStr;
            NSLog(@"chatController.title = %@",chatController.title);
            dispatch_async(dispatch_get_main_queue(),^{
                NSLog(@"回归主线程");
                [self.navigationController pushViewController:chatController animated:YES];
            });
        }else{
            //            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"message"]];
            //            [self showHint:info];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull   error) {
        NSLog(@"====error:%@",error);
        [self hideHud];
        //        [self showHint:@"获取用户信息失败"];
    }];
}

#pragma mark - Mob分享
-(void)HNMobJSExportShare{
    NSLog(@"分享APP");
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        HNShareController *shareVC = [[HNShareController alloc]init];
        shareVC.title = @"分享APP";
        dispatch_async(dispatch_get_main_queue(),^{
            [self.navigationController pushViewController:shareVC animated:YES];
        });
        
    });
}

@end
